home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ClockFrm.cpp
-
- Contains: xxx put contents here xxx
-
- Owned by: Richard Rodseth
-
- Copyright: © 1995 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <3> 10/8/96 TJ Removed include of PartWrap.xh
- <2> 6/20/96 JP 1323103: made some logging optional
- <21> 11/2/95 RR Mods to fix Editor swapping
- <20> 10/18/95 RR 1289153: Recover from exceptions creating
- windows. Store fPlatformWindow pointer in
- ClockFrame, so we can get to it even if
- odWindow isn't successfully created
- <19> 10/17/95 jpa Don't crash closing frames w/o windows
- [1289153]
- <18> 10/5/95 TJ Opps, the last comment was wrong. I removed
- an embeded Comment.
- <17> 10/5/95 TJ Linked in the GX shared library.
- <16> 9/21/95 RR Delete facet iterator
- <15> 9/12/95 RR Various activation problems. Added a
- floating window
- <14> 9/1/95 RR # 1244639 Set and use fShouldDeleteWindow.
- Set fNeedsFoci false
- <13> 7/10/95 RR Misc. cleanup and bug fixes for shared
- window
- <12> 7/7/95 RR Some refactoring. Fix
- CreatePropObjSpecifier to deal with
- non-persistent frame. Set source frame of
- dialogs.
- <11> 7/3/95 RR 1242642 BB: refcounting. NULL out
- TempODWindow after calling CloseAndRemove
- <10> 6/30/95 RR 1242642 BB Ref counting fixes. Display
- settings window is saved as an ID, not a
- window
- <9> 6/28/95 RR 1242642 BB Mostly ref counting
- <8> 6/25/95 TÇ 1242642 BB: Turn on ODDebug warning if
- refcount is wrong in
- ODRefCntObjectsomUninit.
- <7> 6/20/95 JBS 1257315 change Facet::AcquireWindow to
- GetWindow
- <6> 6/13/95 JP Recordable Clock
- <5> 6/12/95 TJ Included ODDebug.h
- <4> 6/8/95 jpa Use temp objects (TempODShape,
- TempODFrame). [1246062]
- <3> 6/8/95 RR #1257260 Collapse base classes. #1214898
- StdTypes.r -> ODTypes.r
- <2> 6/3/95 TJ Added #includes for compile with out PCH
- <1> 5/31/95 RR first checked in
-
- To Do:
- In Progress:
-
- */
-
- #ifndef _ALTPOINT_
- #include "AltPoint.h" // Use C++ savvy ODPoint and ODRect
- #endif
-
- #ifndef _CLOCKFRM_
- #include "ClockFrm.h"
- #endif
-
- #ifndef _CLOCKGBL_
- #include "ClockGbl.h"
- #endif
-
- #ifndef _CLOCKPRT_
- #include "ClockPrt.h"
- #endif
-
- #ifndef _CLOCKDEF_
- #include "ClockDef.h"
- #endif
-
- #ifndef _PLFMDEF_
- #include "PlfmDef.h"
- #endif
-
-
- #ifndef _SIHELPER_
- #include "SIHelper.h"
- #endif
-
- #ifndef SOM_Module_OpenDoc_Foci_defined
- #include <Foci.xh>
- #endif
-
- #ifndef _USERSRCM_
- #include "UseRsrcM.h"
- #endif
-
- #ifndef SOM_ODFocusSet_xh
- #include <FocusSet.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdDefs_defined
- #include <StdDefs.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODDocument_xh
- #include <Document.xh>
- #endif
-
- #ifndef SOM_ODContainer_xh
- #include <ODCtr.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODStorageUnitView_xh
- #include <SUView.xh>
- #endif
-
- #ifndef SOM_ODStorageUnitCursor_xh
- #include <SUCursor.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODFrameFacetIterator_xh
- #include <FrFaItr.xh>
- #endif
-
- #ifndef _ORDCOLL_
- #include "OrdColl.h"
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef SOM_ODMenuBar_xh
- #include <MenuBar.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- #ifndef _ITEXT_
- #include <IText.h>
- #endif
-
- #ifndef _ISOSTRING_
- #include "ISOStr.h"
- #endif
-
- #ifndef SOM_ODMessageInterface_xh
- #include <MssgIntf.xh>
- #endif
-
- #ifndef _AEOBJECTS_
- #include "AEObjects.h"
- #endif
-
- #ifndef _FOCUSLIB_
- #include "FocusLib.h"
- #endif
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __OSUTILS__
- #include <OSUtils.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __SCRIPT__
- #include <Script.h>
- #endif
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __DIALOGS__
- #include "Dialogs.h"
- #endif
-
- #ifndef __TEXTEDIT__
- #include <TextEdit.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __STRINGS__
- #include <Strings.h>
- #endif
-
- #ifndef __FP__
- #include <Fp.h>
- #endif
-
- #include <string.h>
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef _STDTYPIO_
- #include "StdTypIO.h"
- #endif
-
- #ifndef _INFOUTIL_
- #include <InfoUtil.h>
- #endif
-
- #ifndef _WINUTILS_
- #include "WinUtils.h"
- #endif
-
- #ifndef _ITEXT_
- #include <IText.h>
- #endif
-
- #ifndef _PASCLSTR_
- #include "PasclStr.h"
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _POUTILS_
- #include <POUtils.h> // for UpdateModificationInfo
- #endif
-
- #ifndef _TEMPOBJB_
- #include <TempObj.h>
- #endif
-
- //#ifndef SOM_ODPartWrapper_xh
- //#include "PartWrap.xh"
- //#endif
-
- #pragma segment ClockFrame
-
- //=========================================================================
- // ClockFrame
- //=========================================================================
-
- ClockFrame::ClockFrame()
- {
- fArrowCursor = (ODQDGlobals.arrow);
- fFrame = kODNULL;
- fClockPart = kODNULL;
- fHasFoci = kODFalse;
- fNeedsFoci = kODFalse;
- fFocusSet = kODNULL;
- fWindowID = 0;
- fPlatformWindow = kODNULL;
- fShouldDeleteWindow = kODFalse;
- fShouldHideOnSuspend = kODFalse;
- fShowWindowOnResume = kODFalse;
- fShowWindowOnFocus = kODFalse;
- fInBackground = kODFalse;
- }
-
-
- ClockFrame::~ClockFrame()
- {
- }
-
-
- void ClockFrame::InitClockFrame(Environment* ev,
- ODSession* session,
- ODFrame* frame,
- ClockPart* clockPart)
- {
- fSession = session;
- fArbitrator = fSession->GetArbitrator(ev);
- fDispatcher = fSession->GetDispatcher(ev);
- fWindowState = fSession->GetWindowState(ev);
-
- fFrame = frame;
- fClockPart = clockPart;
-
- fFocusSet = fArbitrator->CreateFocusSet(ev);
-
- fSelectionFocus = fSession->Tokenize(ev, kODSelectionFocus);
- fMenuFocus = fSession->Tokenize(ev, kODMenuFocus);
- fKeyFocus = fSession->Tokenize(ev, kODKeyFocus);
- fModalFocus = fSession->Tokenize(ev, kODModalFocus);
- fShouldDeleteWindow = frame->IsRoot(ev);
- fShouldHideOnSuspend = kODFalse;
- }
-
- void ClockFrame::MouseEnter(Environment* ev, ODFacet* facet, ODPoint* where)
- {
- ODUnused(facet);
- ODUnused(where);
- SetCursor(&fArrowCursor);
- }
-
- void ClockFrame::MouseWithin(Environment* ev, ODFacet* facet, ODPoint* where)
- {
- ODUnused(facet);
- ODUnused(where);
- }
-
- void ClockFrame::MouseLeave(Environment* ev, ODFacet* facet)
- {
- ODUnused(facet);
- SetCursor(&fArrowCursor);
- }
-
- ODID ClockTimeFrame::ViewInWindow(Environment *ev)
- {
- ODWindow* window = kODNULL;
-
- window = fWindowState->AcquireWindow(ev, fWindowID);
- if (window)
- {
- window->Select(ev);
- ODReleaseObject(ev, window);
- }
- else
- {
- WindowProperties props;
- fClockPart->GetDefaultWindowProperties(ev, &props, fFrame);
- window = fClockPart->CreateWindow(ev, props, kODNULL);
- fWindowID = window->GetID(ev);
- window->Open(ev);
- window->Show(ev);
- window->Select(ev);
- ODReleaseObject(ev, window);
- }
- return fWindowID;
- }
-
- //------------------------------------------------------------------------------
- // ClockFrame::BeginRelinquishFocus
- //------------------------------------------------------------------------------
-
-
- ODBoolean ClockFrame::BeginRelinquishFocus(Environment *ev,
- ODTypeToken focus,
- ODFrame* proposedFrame)
- {
- ODUnused(proposedFrame);
- ODBoolean result = kODFalse;
-
- ODPart* part = proposedFrame->AcquirePart(ev);
- if ((focus == fModalFocus) && (part != fClockPart->GetPartWrapper()))
- result = kODFalse;
- else
- result = kODTrue;
- ODReleaseObject(ev, part);
- return result;
- }
-
-
- //------------------------------------------------------------------------------
- // ClockFrame::CommitRelinquishFocus
- //------------------------------------------------------------------------------
-
-
- void ClockFrame::CommitRelinquishFocus(Environment *ev,
- ODTypeToken focus,
- ODFrame* proposedFrame)
- {
- //if (proposedFrame->GetPart(ev) != fClockPart->GetPartWrapper())
- this->FocusLost(ev, focus, proposedFrame);
- }
-
-
- //------------------------------------------------------------------------------
- // ClockFrame::AbortRelinquishFocus
- //------------------------------------------------------------------------------
-
-
- void ClockFrame::AbortRelinquishFocus(Environment *ev,
- ODTypeToken focus,
- ODFrame* proposedFrame)
- {
- ODUnused(focus);
- ODUnused(proposedFrame);
- }
-
-
- //------------------------------------------------------------------------------
- // ClockFrame::FocusAcquired
- //------------------------------------------------------------------------------
-
-
- void ClockFrame::FocusAcquired(Environment *ev,
- ODTypeToken focus)
- {
- /* if (focus == fSelectionFocus)
- {
- fHasFoci = kODTrue;
- }
- else if (focus == fMenuFocus)
- fClockPart->InstallMenus(ev);
- */
- }
-
-
- //------------------------------------------------------------------------------
- // ClockFrame::FocusLost
- //------------------------------------------------------------------------------
-
-
- void ClockFrame::FocusLost(Environment *ev,
- ODTypeToken focus, ODFrame* proposedFrame)
- {
- if ( (focus == fSelectionFocus) ||
- (focus == fMenuFocus) ||
- (focus == fKeyFocus) )
- {
- fHasFoci = kODFalse;
- }
-
- if (focus == fSelectionFocus)
- {
- this->LostSelectionFocus(ev, proposedFrame);
-
- }
- }
-
- void ClockFrame::LostSelectionFocus(Environment* ev, ODFrame* proposedFrame)
- {
- ODBoolean samePart =
- (proposedFrame && (proposedFrame->GetPresentation(ev) == fClockPart->fTimePresentation));
- if (!samePart)
- gClockGlobals->SuspendWindows(ev, kODFalse);
- }
-
- void ClockFrame::AcquiredSelectionFocus(Environment* ev)
- {
- gClockGlobals->AcquiringFocus(ev, fFrame);
- gClockGlobals->ResumeWindows(ev, kODFalse);
- }
-
- void ClockFrame::Add(Environment* ev)
- {
- }
-
- void ClockFrame::Connect(Environment* ev)
- {
- }
-
- void ClockFrame::FacetAdded(Environment* ev, ODFacet* facet)
- {
- if (fShouldDeleteWindow)
- {
- ODWindow* window = facet->GetWindow(ev);
- fPlatformWindow = window ? window->GetPlatformWindow(ev) : kODNULL;
- }
- }
-
- void ClockFrame::Remove(Environment* ev)
- {
- fArbitrator->RelinquishFocusSet(ev, fFocusSet,fFrame);
- ODWindow* window = fWindowState->AcquireWindow(ev, fWindowID); // -- TÇ: released by CloseAndRemove
- if (window)
- {
- window->CloseAndRemove(ev);
- // ODReleaseObject(ev, window); // -- TÇ: released by CloseAndRemove
- }
-
- this->DisposePlatformWindow(ev);
- }
-
- void ClockFrame::Close(Environment* ev)
- {
- fArbitrator->RelinquishFocusSet(ev, fFocusSet,fFrame);
- ODWindow* window = fWindowState->AcquireWindow(ev, fWindowID); // -- TÇ: released by CloseAndRemove
- if (window)
- {
- window->Close(ev);
- // ODReleaseObject(ev, window); // -- TÇ: released by Close
- }
-
- this->DisposePlatformWindow(ev);
- }
-
- void ClockFrame::DisposePlatformWindow(Environment *ev)
- {
- if (fShouldDeleteWindow)
- {
- CloseWindow(fPlatformWindow);
- ODDisposePtr(fPlatformWindow);
- }
- }
-
- void ClockFrame::AdjustMenus(Environment *ev)
- {
- fClockPart->AdjustMenus(ev);
- }
-
- ODBoolean ClockFrame::HandleMenuEvent(Environment* ev, ODEventData* event)
- {
- return fClockPart->HandleMenuEvent(ev, event, fFrame);
- }
-
- //=========================================================================
- // ClockTimeFrame
- //=========================================================================
-
- ClockTimeFrame::ClockTimeFrame()
- {
- fCrossCursor = (ODQDGlobals.arrow);
- fLastTime = 0;
- };
-
- ClockTimeFrame::~ClockTimeFrame()
- {
- }
-
- void ClockTimeFrame::InitClockTimeFrame(Environment* ev,
- ODSession* session,
- ODFrame* frame,
- ClockPart* clockPart)
- {
- this->InitClockFrame(ev, session, frame, clockPart);
- fCrossCursor = **GetCursor(crossCursor);
-
- fFocusSet->Add(ev, fKeyFocus);
- fFocusSet->Add(ev, fMenuFocus);
- fFocusSet->Add(ev, fSelectionFocus);
-
- if (frame->IsRoot(ev))
- fNeedsFoci = kODTrue;
- }
-
- void ClockTimeFrame::MouseEnter(Environment* ev, ODFacet* facet, ODPoint* where)
- {
- ODUnused(where);
- ODUnused(facet);
- //SetCursor(&fCrossCursor);
- SetCursor(&fArrowCursor);
- }
-
- void ClockTimeFrame::Idle(Environment* ev, ODEventData* event)
- {
- ODBoolean wasHandled = kODFalse;
- ODULong tTickCount = 0;
-
- GetDateTime( &tTickCount );
-
-
- DateTimeRec time;
- DateTimeRec lastTime;
-
- ::SecondsToDate(tTickCount, &time);
- ::SecondsToDate(fLastTime, &lastTime);
-
- if (lastTime.second != time.second)
- //if ( (tTickCount + 60) > fLastTime )
- {
- ODFrameFacetIterator* facets = fFrame->CreateFacetIterator(ev);
- for ( ODFacet* facet = facets->First(ev);
- facets->IsNotComplete(ev);
- facet = facets->Next(ev) )
- {
- this->UpdateTime(ev, facet, tTickCount);
- }
- delete facets;
- }
-
- if (fClockPart->AlarmEnabled() ) // && (tTickCount % 10 == 0))
- {
- if (tTickCount % 10 == 0)
- gClockGlobals->CloseDisplaySettingsWindow(ev);
- if (tTickCount % 12 == 0)
- gClockGlobals->OpenDisplaySettingsDialog(ev, fFrame);
- /*
- TempODFrame focusFrame = fArbitrator->AcquireFocusOwner(ev, fModalFocus);
-
- if (focusFrame == fFrame)
- SysBeep(2);
- else if (fArbitrator->RequestFocus(ev, fModalFocus,fFrame))
- {
- ODSLong savedRefNum;
- BeginUsingLibraryResources(savedRefNum);
- ParamText("\pWake Up!",0,0,0);
- ModalFilterUPP modalFilter = NewModalFilterProc(ClockDialogFilter);
- fWindowState->DeactivateFrontWindows(ev);
- Alert(kClock_AlarmDialogID, modalFilter);
- DisposeRoutineDescriptor(modalFilter);
- fWindowState->ActivateFrontWindows(ev);
- fArbitrator->TransferFocus(ev, fModalFocus,fFrame, focusFrame);
- EndUsingLibraryResources(savedRefNum);
-
- }
- else
- SysBeep(2);
- */
- }
- }
-
- void ClockTimeFrame::Draw(Environment* ev, ODFacet* facet, ODShape* invalShape)
- {
- if (facet)
- {
- CFocus focus(ev, facet); // Set port, origin, clip
-
- this->DrawClockFace(ev, facet);
- this->DrawTime(ev, facet, fLastTime);
- }
-
- }
-
- void ClockTimeFrame::DrawDigitalTime(Environment* ev, ODFacet* facet, ODULong tickCount)
- {
- // Assumes port is set
- Str255 tTimeString; // pascal string holding date to draw
-
- TextFont(fClockPart->GetFont() );
- TextFace(fClockPart->GetStyle() );
- TextMode(srcCopy);
- TextSize(fClockPart->GetSize() );
-
- IUTimeString( tickCount, kODTrue, tTimeString );
-
- if (fClockPart->GetLastAscent() == 0)
- {
- FontInfo fontIRec;
- GetFontInfo( &fontIRec );
- fClockPart->SetLastAscent(fontIRec.ascent);
- }
-
- MoveTo( 2, fClockPart->GetLastAscent() + 1 );
- DrawString( tTimeString );
-
- TextFace( normal );
- TextFont( geneva );
- TextMode( srcOr );
- TextSize( 12 );
- }
-
- void ClockTimeFrame::UpdateTime(Environment* ev, ODFacet* facet, ODULong tickCount)
- {
- CFocus focus(ev, facet);
- if (fClockPart->IsAnalog())
- this->UpdateClockHands(ev, facet, tickCount);
- else
- this->DrawDigitalTime(ev, facet, tickCount);
- fLastTime = tickCount;
- }
-
- void ClockTimeFrame::DrawTime(Environment* ev, ODFacet* facet, ODULong tickCount)
- {
- if (fClockPart->IsAnalog())
- this->DrawClockHands(ev, facet, tickCount);
- else
- this->DrawDigitalTime(ev, facet, tickCount);
- }
-
- ODBoolean ClockTimeFrame::HandleMouseDown(Environment* ev, ODFacet* facet, ODEventData* event)
- {
- ODBoolean wasHandled = kODFalse;
-
- if (!facet->GetWindow(ev)->IsActive(ev))
- facet->GetWindow(ev)->Select(ev);
- else
- {
- // A test: option-click doesn't go to container, and clock beeps
- ODBoolean modified = (event->modifiers & optionKey) != 0;
- if (modified)
- {
- SysBeep(2);
- }
- else
- this->Activate(ev);
- }
-
- return wasHandled;
- }
-
- ODBoolean ClockTimeFrame::HandleMouseUp(Environment* ev, ODFacet* facet, ODEventData* event)
- {
- if ( facet == kODNULL )
- return kODTrue;
- if (!facet->GetWindow(ev)->IsActive(ev))
- facet->GetWindow(ev)->Select(ev);
- else
- {
- this->Activate(ev);
- }
- return kODTrue;
- }
-
-
- void ClockTimeFrame::AcquiredRequestedFoci(Environment* ev)
- {
- this->AcquiredSelectionFocus(ev);
- fClockPart->InstallMenus(ev);
- }
-
- void ClockFrame::Activate(Environment* ev)
- {
- if (!fHasFoci)
- {
- ODBoolean succeeded = kODFalse;
-
- succeeded = fArbitrator->RequestFocusSet(ev, fFocusSet,fFrame);
-
- if (succeeded)
- {
- fHasFoci = kODTrue;
- fNeedsFoci = kODFalse;
- this->AcquiredRequestedFoci(ev);
- }
- }
- }
-
- void ClockFrame::ActivatingWindow(Environment* ev, ODFacet* facet, ODEventData* event)
- {
- #if defined(ODDebug) && ODDebugLayers
- somPrintf("Activating window of Clock\n");
- #endif
-
- if (fNeedsFoci)
- {
- this->Activate(ev);
- }
- fNeedsFoci = kODFalse;
- }
-
- void ClockFrame::DeactivatingWindow(Environment* ev, ODFacet* facet, ODEventData* event)
- {
- #if defined(ODDebug) && ODDebugLayers
- somPrintf("Deactivating window of Clock\n");
- #endif
-
- if (fHasFoci) // (fFrame == fArbitrator->AcquireFocusOwner(ev, fSelectionFocus))
- {
- fNeedsFoci = kODTrue;
- }
- else
- fNeedsFoci = kODFalse;
- }
-
- void ClockFrame::SuspendFocus(Environment* ev)
- {
- #if defined(ODDebug) && ODDebugLayers
- somPrintf("ClockFrame::SuspendFocus - should hide %x\n", fShouldHideOnSuspend);
- #endif
- if (fFrame->IsRoot(ev) && fShouldHideOnSuspend)
- {
- TempODWindow window = fFrame->AcquireWindow(ev);
- if (window->IsShown(ev))
- {
- window->Hide(ev);
- fShowWindowOnFocus = kODTrue;
- }
- else
- {
- fShowWindowOnFocus = kODFalse;
- }
- }
- }
-
- void ClockFrame::ResumeFocus(Environment* ev)
- {
- #if defined(ODDebug) && ODDebugLayers
- somPrintf("ClockFrame::ResumeFocus - should show %x\n", fShowWindowOnFocus);
- #endif
- if (fFrame->IsRoot(ev) && fShouldHideOnSuspend)
- {
- TempODWindow window = fFrame->AcquireWindow(ev);
- if (fShowWindowOnFocus && !fInBackground)
- {
- fShowWindowOnFocus = kODFalse;
- window->Show(ev);
- }
- }
- }
-
- void ClockFrame::SuspendProcess(Environment* ev)
- {
- fInBackground = kODTrue;
- #if defined(ODDebug) && ODDebugLayers
- somPrintf("ClockFrame::SuspendProcess - should hide %x\n", fShouldHideOnSuspend);
- #endif
- if (fFrame->IsRoot(ev) && fShouldHideOnSuspend)
- {
- TempODWindow window = fFrame->AcquireWindow(ev);
- if (window->IsShown(ev))
- {
- fShowWindowOnResume = kODTrue;
- window->Hide(ev);
- }
- else
- {
- fShowWindowOnResume = kODFalse;
- }
- }
- }
-
- void ClockFrame::ResumeProcess(Environment* ev)
- {
- fInBackground = kODFalse;
- #if defined(ODDebug) && ODDebugLayers
- somPrintf("ClockFrame::ResumeProcess - should show %x\n", fShowWindowOnResume);
- #endif
- if (fFrame->IsRoot(ev) && fShouldHideOnSuspend)
- {
- TempODWindow window = fFrame->AcquireWindow(ev);
- if (fShowWindowOnResume)
- {
- fShowWindowOnResume = kODFalse; // It may be hidden by user before next Suspend
- fShowWindowOnFocus = kODFalse;
- window->Show(ev);
- }
- }
- }
-
-
- void ClockTimeFrame::AdjustMenus(Environment *ev)
- {
- TempODWindow window = fFrame->AcquireWindow(ev);
- fClockPart->AdjustMenus(ev);
-
- fClockPart->GetMenuBar()->EnableCommand(ev, kODCommandViewAsWin, !fFrame->IsRoot(ev));
- fClockPart->GetMenuBar()->EnableCommand(ev, cNewView, fFrame->IsRoot(ev) && window->IsRootWindow(ev));
- }
-
- void ClockTimeFrame::Adjust(Environment* ev)
- {
- this->AdjustFrameShape(ev);
- }
-
- //------------------------------------------------------------------------------
- // ClockTimeFrame: HandleMenuEvent
- //------------------------------------------------------------------------------
-
-
- ODBoolean ClockTimeFrame::HandleMenuEvent(Environment *ev, ODEventData* event)
- {
- ODBoolean wasHandled = kODTrue;
-
- long menuResult = event->message;
- short menu = HiWord(menuResult);
- short item = LoWord(menuResult);
- ODCommandID command = fClockPart->GetMenuBar()->GetCommand(ev, menu, item);
-
- switch (command)
- {
- //case kODCommandAbout:
- // fClockPart->ShowAboutBox(ev, fFrame);
- wasHandled = kODTrue;
- break;
- case kODCommandViewAsWin:
- this->ViewInWindow(ev);
- wasHandled = kODTrue;
- break;
- case kODCommandClose:
- wasHandled = fClockPart->CloseWindow(ev, fFrame);
- break;
- /*case cSynchronize:
- fClockPart->ShowSynchDialog(ev);
- wasHandled = kODTrue;
- break;
- case cShowAlarmSettings:
- fClockPart->ShowAlarmSettingsDialog(ev);
- wasHandled = kODTrue;
- break;
- case cShowDisplaySettings:
- gClockGlobals->OpenDisplaySettingsDialog(ev, fFrame);
- fClockPart->AdjustDialogs(ev);
- wasHandled = kODTrue;
- break;
- */
- case cNewView:
- fClockPart->OpenInitialWindow(ev);
- fWindowState->SetDefaultWindowTitles(ev, fFrame->GetStorageUnit(ev)->GetDraft(ev));
- wasHandled = kODTrue;
- break;
- default:
- wasHandled = kODFalse;
- break;
- }
- if (wasHandled)
- return kODTrue;
- else
- return ClockFrame::HandleMenuEvent(ev, event);
- }
-
-
-
-
- //------------------------------------------------------------------------------
- // ClockTimeFrame: AdjustFrameShape
- //------------------------------------------------------------------------------
-
-
- void ClockTimeFrame::AdjustFrameShape(Environment *ev)
- {
- if (fFrame->IsRoot(ev))
- {
- fFrame-> Invalidate(ev, kODNULL, kODNULL);
- this->FitToFrameShape(ev);
- return;
- }
-
- Rect qdr;
- fClockPart->CalcClockBounds(qdr);
- ODRect r(qdr);
-
- TempODShape oldShape = fFrame->AcquireFrameShape(ev, kODNULL);
- TempODShape wantShape = fFrame->CreateShape(ev);
-
- wantShape->SetRectangle(ev, &r);
-
- if ( !wantShape->IsSameAs(ev, oldShape) )
- {
- //fFrame-> Invalidate(ev, kODNULL, kODNULL); // $$$$$ container responsible for old shape
-
- ODShape* gotShape = fFrame -> RequestFrameShape(ev, wantShape, kODNULL );
- ODReleaseObject(ev, gotShape);
-
- this->FitToFrameShape(ev); // Adjust used shape to frame shape
- }
-
- fFrame-> Invalidate(ev, kODNULL, kODNULL);
- }
-
- void ClockTimeFrame::FrameShapeChanged(Environment *ev)
- {
- fFrame-> Invalidate(ev, kODNULL, kODNULL);
- this->FitToFrameShape(ev);
- }
-
- static inline short Width(const Rect& r)
- {
- return r.right - r.left;
- }
-
- static inline short Height(const Rect& r)
- {
- return r.bottom - r.top;
- }
-
- static inline void CenterRect(const Rect& outer, Rect& inner)
- {
- short x = (Width(outer) - Width(inner)) / 2;
- short y = (Height(outer) - Height(inner)) / 2;
-
- inner.right += x - inner.left;
- inner.left = x;
- inner.bottom += y - inner.top;
- inner.top = y;
- }
-
-
-
- void ClockTimeFrame::FitToFrameShape(Environment *ev)
- {
- // Update used shape of frame and active shape of all facets
- // invalidate frame shape
- // invalidate active border
-
- Rect frameShapeRect;
- Rect usedShapeRect;
- ODShape* newUsedShape = kODNULL;
-
- {
- TempODShape frameShape = fFrame->AcquireFrameShape(ev, kODNULL);
- ODRgnHandle shapeRegion = frameShape->GetQDRegion(ev);
- frameShapeRect = (*shapeRegion)->rgnBBox;
- }
-
- if (fClockPart->IsAnalog())
- {
- if (fFrame->IsRoot(ev))
- {
- frameShapeRect.right = frameShapeRect.right - 16;
- frameShapeRect.bottom = frameShapeRect.bottom - 16;
- }
- usedShapeRect = frameShapeRect;
- if (usedShapeRect.bottom > usedShapeRect.right)
- usedShapeRect.bottom = usedShapeRect.right;
- else
- usedShapeRect.right = usedShapeRect.bottom;
-
- }
- else
- {
- fClockPart->CalcClockBounds(usedShapeRect);
- }
- if (fClockPart->IsAnalog())
- CenterRect(frameShapeRect, usedShapeRect);
-
- if (fClockPart->IsAnalog())
- {
- /*
- ODRect u(usedShapeRect);
- newUsedShape = fFrame->CreateShape(ev);
- newUsedShape->SetRectangle(ev, &u);
- */
- newUsedShape = fClockPart->CreateOvalShape(ev, fFrame, usedShapeRect);
- }
- else
- {
- ODRect u(usedShapeRect);
- newUsedShape = fFrame->CreateShape(ev);
- newUsedShape->SetRectangle(ev, &u);
- }
-
- /* This is an alternative to the SetOrigin calls. But then we need to
- undo the transformation to draw the border. It would be nice if CFocus
- provide an easy way to mix internal/external transforms.
-
- ODTransform* internal = fFrame->CreateTransform(ev);
- Point offset;
- offset.h = usedShapeRect.left;
- offset.v = usedShapeRect.top;
- internal->SetQDOffset(ev, &offset);
- fFrame->ChangeInternalTransform(ev, internal, kODNULL);
- internal->Release(ev);
- */
-
- fFrame->ChangeUsedShape(ev, newUsedShape, kODNULL);
-
- ODShape* activeShape = newUsedShape->Copy(ev);
- /*if (fHasFoci)
- {
- ODRect u2(usedShapeRect);
- activeShape->SetRectangle(ev, &u2);
- }*/
- ODFrameFacetIterator* fi = fFrame->CreateFacetIterator(ev);
- for(ODFacet* facet = fi->First(ev); fi->IsNotComplete(ev);
- facet = fi->Next(ev))
- {
- facet->ChangeActiveShape(ev,activeShape, kODNULL);
- }
- ODDeleteObject(fi);
- activeShape->Release(ev);
-
- newUsedShape->Release(ev);
- }
-
- void ClockTimeFrame::FacetAdded(Environment* ev, ODFacet* facet)
- {
- ClockFrame::FacetAdded(ev, facet);
- this->AdjustFrameShape(ev);
- }
-
- void ClockTimeFrame::Add(Environment* ev)
- {
- ClockFrame::Add(ev);
- fClockPart->AddContentFrame(ev, fFrame);
- fDispatcher->RegisterIdle(ev, fClockPart->GetPartWrapper(), fFrame, kCPIdleFrequency );
- }
-
- void ClockTimeFrame::Connect(Environment* ev)
- {
- ClockFrame::Connect(ev);
- fClockPart->AddContentFrame(ev, fFrame);
- fDispatcher->RegisterIdle(ev, fClockPart->GetPartWrapper(), fFrame, kCPIdleFrequency );
- }
-
- void ClockTimeFrame::Remove(Environment* ev)
- {
- fDispatcher->UnregisterIdle(ev, fClockPart->GetPartWrapper(), fFrame );
- gClockGlobals->RemovingFrame(ev, fFrame);
- fClockPart->RemoveContentFrame(ev, fFrame);
- ClockFrame::Remove(ev);
- }
-
- void ClockTimeFrame::Close(Environment* ev)
- {
- fDispatcher->UnregisterIdle(ev, fClockPart->GetPartWrapper(), fFrame );
- gClockGlobals->RemovingFrame(ev, fFrame);
- fClockPart->RemoveContentFrame(ev, fFrame);
- ClockFrame::Close(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // ClockTimeFrame::DrawClockFace
- //----------------------------------------------------------------------------------------
-
- void ClockTimeFrame::DrawClockFace(Environment* ev, ODFacet* facet)
- {
- Rect frameRect, usedRect;
- {
- TempODShape frameShape = fFrame->AcquireFrameShape(ev, kODNULL);
- TempODShape usedShape = fFrame->AcquireUsedShape(ev, kODNULL);
- ODRgnHandle frameRegion = frameShape->GetQDRegion(ev);
- frameRect = (*frameRegion)->rgnBBox;
- ODRgnHandle usedRegion = usedShape->GetQDRegion(ev);
- usedRect = (*usedRegion)->rgnBBox;
- }
-
- if (fClockPart->IsAnalog())
- {
- if (fFrame->IsRoot(ev))
- ::EraseRect(&frameRect);
- else
- ::EraseOval(&usedRect);
- //::EraseRect(&usedRect);
-
- this->DrawAnalogFace(ev, facet);
- }
- else
- {
- if (fFrame->IsRoot(ev))
- ::EraseRect(&frameRect);
- else
- ::EraseRect(&usedRect);
-
- ::FrameRect(&usedRect);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // ClockTimeFrame::DrawAnalogFace
- //----------------------------------------------------------------------------------------
-
- void ClockTimeFrame::DrawAnalogFace(Environment* ev, ODFacet* facet)
- {
- Point currentPenSize = ODQDGlobals.thePort->pnSize;
- // TextStyle currentTextStyle;
- Point centerPoint;
- Point newPoint;
- Point tickPoint;
- ODSShort radius;
- ODSShort angle = 0;
- ODSShort fiveMinute = 0;
- double_t radians;
-
- // ::GetPortTextStyle(¤tTextStyle);
-
- Rect clockRect;
- {
- TempODShape usedShape = fFrame->AcquireUsedShape(ev, kODNULL);
- ODRgnHandle shapeRegion = usedShape->GetQDRegion(ev);
- clockRect = (*shapeRegion)->rgnBBox;
- }
-
- centerPoint.h = (clockRect.right - clockRect.left) / 2;
- centerPoint.v = (clockRect.bottom - clockRect.top) / 2;
- radius = centerPoint.h;
-
- ::EraseOval(&clockRect);
-
- ::PenSize(2,2);
- ::FrameOval(&clockRect);
- ::PenSize(1,1);
-
- ::TextFont(helvetica);
- //::TextFace(italic);
- ::TextSize(radius / 10);
-
- /* $$$$$ Added */
- Point oldOrigin;
- Point newOrigin;
- oldOrigin.h = ODQDGlobals.thePort->portRect.left;
- oldOrigin.v = ODQDGlobals.thePort->portRect.top;
- newOrigin.h = oldOrigin.h - clockRect.left;
- newOrigin.v = oldOrigin.v - clockRect.top;
- SetOrigin(newOrigin.h,newOrigin.v);
- // */
-
- Str255 clockFaceString = "\pOpenDoc™";
- //FW_CAcquireASLMResourceAccess aq;
- //::GetIndString(clockFaceString, kClockPartStrings, kClockFaceString);
-
- ::MoveTo(((clockRect.right - clockRect.left) - ::StringWidth(clockFaceString)) / 2, (clockRect.bottom - clockRect.top) / 4);
- ::DrawString(clockFaceString);
-
-
- //!!!!! Should save/restore
- TextFace( normal );
- TextFont( geneva );
- TextMode( srcOr );
- TextSize( 12 );
-
-
-
- // Use the symmetry of the clock face to speed up the calculations for drawing the face
- // We only need to calculate points for 45 degrees of the circle. The remaining points can
- // be inferred from these points
- while (angle < 45)
- {
- // convert angle to radians
- radians = (90 - angle) / (360 / (2 * pi));
- newPoint.h = (short)::rint((radius * cos(radians)) + centerPoint.h);
- newPoint.v = (short)::rint((radius * sin(radians)) + centerPoint.v);
-
- if (fiveMinute == 0)
- {
- short hourTick = radius - (radius / 10);
- tickPoint.h = (short)::rint((hourTick * cos(radians)) + centerPoint.h);
- tickPoint.v = (short)::rint((hourTick * sin(radians)) + centerPoint.v);
- fiveMinute = 4;
- }
- else
- {
- short minuteTick = radius - (radius / 20);
- tickPoint.h = (short)::rint((minuteTick * cos(radians)) + centerPoint.h);
- tickPoint.v = (short)::rint((minuteTick * sin(radians)) + centerPoint.v);
- fiveMinute--;
- }
-
- ::MoveTo(newPoint.h - 1, newPoint.v - 1);
- ::LineTo(tickPoint.h - 1, tickPoint.v - 1);
-
- ::MoveTo((clockRect.right-clockRect.left) - newPoint.h, newPoint.v - 1);
- ::LineTo((clockRect.right-clockRect.left) - tickPoint.h, tickPoint.v - 1);
-
- ::MoveTo(newPoint.h - 1, (clockRect.bottom-clockRect.top) - newPoint.v);
- ::LineTo(tickPoint.h - 1, (clockRect.bottom-clockRect.top) - tickPoint.v);
-
- ::MoveTo((clockRect.right-clockRect.left) - newPoint.h, (clockRect.bottom-clockRect.top) - newPoint.v);
- ::LineTo((clockRect.right-clockRect.left) - tickPoint.h, (clockRect.bottom-clockRect.top) - tickPoint.v);
-
- ::MoveTo(newPoint.v - 1, newPoint.h - 1);
- ::LineTo(tickPoint.v - 1, tickPoint.h - 1);
-
- ::MoveTo((clockRect.bottom-clockRect.top) - newPoint.v, newPoint.h - 1);
- ::LineTo((clockRect.bottom-clockRect.top) - tickPoint.v, tickPoint.h - 1);
-
- ::MoveTo(newPoint.v - 1, (clockRect.right-clockRect.left) - newPoint.h);
- ::LineTo(tickPoint.v - 1, (clockRect.right-clockRect.left) - tickPoint.h);
-
- ::MoveTo((clockRect.bottom-clockRect.top) - newPoint.v, (clockRect.right-clockRect.left) - newPoint.h);
- ::LineTo((clockRect.bottom-clockRect.top) - tickPoint.v, (clockRect.right-clockRect.left) - tickPoint.h);
-
- angle += 6;
- }
-
- SetOrigin(oldOrigin.h,oldOrigin.v);
-
-
- ::PenSize(currentPenSize.h, currentPenSize.v);
- // ::SetPortTextStyle(¤tTextStyle);
- }
-
- //----------------------------------------------------------------------------------------
- // ClockTimeFrame::DrawClockHands
- //----------------------------------------------------------------------------------------
- void ClockTimeFrame::DrawClockHands(Environment* ev, ODFacet* facet, ODULong tickCount)
- {
- ODSShort currentPenMode = ODQDGlobals.thePort->pnMode;
- Point centerPoint;
- DateTimeRec time;
-
- Rect clockRect;
- {
- TempODShape usedShape = fFrame->AcquireUsedShape(ev, kODNULL);
- ODRgnHandle shapeRegion = usedShape->GetQDRegion(ev);
- clockRect = (*shapeRegion)->rgnBBox;
- }
-
- /* $$$$$ Added */
- Point oldOrigin;
- Point newOrigin;
- oldOrigin.h = ODQDGlobals.thePort->portRect.left;
- oldOrigin.v = ODQDGlobals.thePort->portRect.top;
- newOrigin.h = oldOrigin.h - clockRect.left;
- newOrigin.v = oldOrigin.v - clockRect.top;
- SetOrigin(newOrigin.h,newOrigin.v);
- // */
-
- centerPoint.h = (clockRect.right - clockRect.left) / 2;
- centerPoint.v = (clockRect.bottom - clockRect.top) / 2;
-
- ::SecondsToDate(tickCount, &time);
-
- PenMode(patXor);
- this->DrawSecondHand(&clockRect, ¢erPoint, centerPoint.h, time.second);
- this->DrawMinuteHand(&clockRect, ¢erPoint, centerPoint.h, time.minute);
-
- if (time.hour > 11)
- this->DrawHourHand(&clockRect, ¢erPoint, centerPoint.h, time.hour - 12, time.minute);
- else
- this->DrawHourHand(&clockRect, ¢erPoint, centerPoint.h, time.hour, time.minute);
-
- ::PenMode(currentPenMode);
-
- //$$$$$Added
- SetOrigin(oldOrigin.h, oldOrigin.v);
- }
-
- //----------------------------------------------------------------------------------------
- // ClockTimeFrame::UpdateClockHands
- //----------------------------------------------------------------------------------------
- void ClockTimeFrame::UpdateClockHands(Environment* ev, ODFacet* facet, ODULong tickCount)
- {
- ODSShort currentPenMode = ODQDGlobals.thePort->pnMode;
- Point centerPoint;
- DateTimeRec time;
- DateTimeRec lastTime;
-
-
-
-
- ::GetDateTime(&tickCount);
- ::SecondsToDate(tickCount, &time);
- ::SecondsToDate(fLastTime, &lastTime);
-
- Rect clockRect;
- {
- TempODShape usedShape = fFrame->AcquireUsedShape(ev, kODNULL);
- ODRgnHandle shapeRegion = usedShape->GetQDRegion(ev);
- clockRect = (*shapeRegion)->rgnBBox;
- }
-
- /* $$$$$ Added */
- Point oldOrigin;
- Point newOrigin;
- oldOrigin.h = ODQDGlobals.thePort->portRect.left;
- oldOrigin.v = ODQDGlobals.thePort->portRect.top;
- newOrigin.h = oldOrigin.h - clockRect.left;
- newOrigin.v = oldOrigin.v - clockRect.top;
- SetOrigin(newOrigin.h,newOrigin.v);
- // */
-
- centerPoint.h = (clockRect.right - clockRect.left) / 2;
- centerPoint.v = (clockRect.bottom - clockRect.top) / 2;
-
- ::PenMode(patXor);
-
- // Since we're called every second go ahead and update the second hand
- this->DrawSecondHand(&clockRect, ¢erPoint, centerPoint.h, lastTime.second);
- this->DrawSecondHand(&clockRect, ¢erPoint, centerPoint.h, time.second);
-
- if (lastTime.minute != time.minute)
- {
- this->DrawMinuteHand(&clockRect, ¢erPoint, centerPoint.h, lastTime.minute);
- this->DrawMinuteHand(&clockRect, ¢erPoint, centerPoint.h, time.minute);
-
- if (lastTime.hour > 11)
- this->DrawHourHand(&clockRect, ¢erPoint, centerPoint.h, lastTime.hour - 12, lastTime.minute);
- else
- this->DrawHourHand(&clockRect, ¢erPoint, centerPoint.h, lastTime.hour, lastTime.minute);
-
- if (time.hour > 11)
- this->DrawHourHand(&clockRect, ¢erPoint, centerPoint.h, time.hour - 12, time.minute);
- else
- this->DrawHourHand(&clockRect, ¢erPoint, centerPoint.h, time.hour, time.minute);
- }
-
- ::PenMode(currentPenMode);
- //$$$$$Added
- SetOrigin(oldOrigin.h, oldOrigin.v);
- }
-
- //----------------------------------------------------------------------------------------
- // ClockTimeFrame::DrawHourHand
- //----------------------------------------------------------------------------------------
- void ClockTimeFrame::DrawHourHand(Rect* clockRect, Point* centerPoint, ODSShort radius, ODSShort hour, ODSShort minute)
- {
- Point currentPenSize = ODQDGlobals.thePort->pnSize;
- Point newPoint;
- double_t radians;
- ODSShort hourRadius = radius / 2; // Make the hour hand short and stubby
-
- // Divide the clock face into degrees. Hour hand falls on every five minutes or every 30 degrees
- radians = ((hour * 30) + (minute / 2)) / (360 / (2 * pi));
- newPoint.h = (short)::rint((hourRadius * ::sin(radians)) + centerPoint->h);
- newPoint.v = clockRect->bottom-clockRect->top - ((short)::rint((hourRadius * ::cos(radians)) + centerPoint->v));
-
- ::PenSize(3,3);
- ::MoveTo(centerPoint->h, centerPoint->v);
- ::LineTo(newPoint.h - 1, newPoint.v);
- ::PenSize(currentPenSize.h, currentPenSize.v);
- }
-
- //----------------------------------------------------------------------------------------
- // ClockTimeFrame::DrawMinuteHand
- //----------------------------------------------------------------------------------------
- void ClockTimeFrame::DrawMinuteHand(Rect* clockRect, Point* centerPoint, ODSShort radius, ODSShort minute)
- {
- Point currentPenSize = ODQDGlobals.thePort->pnSize;
- Point newPoint;
- double_t radians;
- ODSShort minuteRadius = radius - (radius / 20); // Make the minute hand longer than the hour hand
-
- // Divide the clock face into degrees. (360 degrees divided by 60 minutes is 6 degrees per minute)
- radians = (minute * 6) / (360 / (2 * pi));
- newPoint.h = (short)::rint((minuteRadius * ::sin(radians)) + centerPoint->h);
- newPoint.v = clockRect->bottom-clockRect->top - ((short)::rint((minuteRadius * ::cos(radians)) + centerPoint->v));
-
- ::PenSize(2,2);
- ::MoveTo(centerPoint->h, centerPoint->v);
- ::LineTo(newPoint.h - 1, newPoint.v);
- ::PenSize(currentPenSize.h, currentPenSize.v);
- }
-
- //----------------------------------------------------------------------------------------
- // ClockTimeFrame::DrawSecondHand
- //----------------------------------------------------------------------------------------
- void ClockTimeFrame::DrawSecondHand(Rect* clockRect, Point* centerPoint, ODSShort radius, ODSShort second)
- {
- Point currentPenSize = ODQDGlobals.thePort->pnSize;
- Point newPoint;
-
- double_t radians;
- ODSShort secondRadius = radius - (radius / 40); // A nice sweeping second hand
-
- // Divide the clock face into degrees. (360 degrees divided by 60 seconds is 6 degrees per second)
- radians = (second * 6) / (360 / (2 * pi));
- newPoint.h = (short)::rint((secondRadius * ::sin(radians)) + centerPoint->h);
- newPoint.v = clockRect->bottom-clockRect->top - ((short)::rint((secondRadius * ::cos(radians)) + centerPoint->v));
-
- ::PenSize(1,1);
- ::MoveTo(centerPoint->h, centerPoint->v);
- ::LineTo(newPoint.h - 1, newPoint.v);
- ::PenSize(currentPenSize.h, currentPenSize.v);
- }
-
-
- //=========================================================================
- // ClockDialogFrame
- //=========================================================================
-
- ClockDialogFrame::ClockDialogFrame()
- {
- }
-
- ClockDialogFrame::~ClockDialogFrame()
- {
- }
-
- void ClockDialogFrame::InitClockDialogFrame(Environment* ev,
- ODSession* session,
- ODFrame* frame,
- ClockPart* clockPart)
- {
- this->InitClockFrame(ev, session, frame, clockPart);
-
- fFocusSet->Add(ev, fKeyFocus);
- fFocusSet->Add(ev, fMenuFocus);
-
- fShouldHideOnSuspend = kODTrue;
- }
-
- void ClockDialogFrame::Draw(Environment* ev, ODFacet* facet, ODShape* invalShape)
- {
- ODWindow* odWindow = facet ? facet->GetWindow(ev) : kODNULL;
- WindowPtr window = odWindow ? odWindow->GetPlatformWindow(ev) : kODNULL;
- if (window)
- DrawDialog(window);
- else
- WARN("dialog ptr is NULL");
- }
-
- void ClockDialogFrame::Idle(Environment* ev, ODEventData* event)
- {
- if (IsDialogEvent((const EventRecord *)event))
- {
- short itemHit;
- DialogPtr dialog;
- ODBoolean wasHandled = DialogSelect((const EventRecord *)event, &dialog, &itemHit);
- }
- }
-
- void ClockDialogFrame::Add(Environment* ev)
- {
- ClockFrame::Add(ev);
- #if defined(ODDebug) && ODDebugLayers
- somPrintf("ClockDialogFrame::Add. Adding Dialog Frame\n");
- #endif
- gClockGlobals->AddDialogFrame(ev, fFrame);
- }
-
- void ClockDialogFrame::Connect(Environment* ev)
- {
- ClockFrame::Connect(ev);
- gClockGlobals->AddDialogFrame(ev, fFrame);
- }
-
- void ClockDialogFrame::Remove(Environment* ev)
- {
- ClockFrame::Remove(ev);
- gClockGlobals->RemoveDialogFrame(ev, fFrame);
- }
-
- void ClockDialogFrame::Close(Environment* ev)
- {
- ClockFrame::Close(ev);
- gClockGlobals->RemoveDialogFrame(ev, fFrame);
- }
-
- //=========================================================================
- // ClockSynchroDialogFrame
- //=========================================================================
-
- ClockSynchroDialogFrame::ClockSynchroDialogFrame()
- {
- }
-
- ClockSynchroDialogFrame::~ClockSynchroDialogFrame()
- {
- }
-
- void ClockSynchroDialogFrame::InitClockSynchroDialogFrame(Environment* ev,
- ODSession* session,
- ODFrame* frame,
- ClockPart* clockPart)
- {
- this->InitClockDialogFrame(ev, session, frame, clockPart);
- fNeedsFoci = kODTrue;
- }
-
- ODBoolean ClockSynchroDialogFrame::HandleMouseDown(Environment* ev, ODFacet* facet, ODEventData* event)
- {
- ODBoolean wasHandled = kODFalse;
-
- if (IsDialogEvent((const EventRecord *)event))
- {
- short itemHit;
- DialogPtr dialog;
- wasHandled = DialogSelect((const EventRecord *)event, &dialog, &itemHit);
- ODWindow* window = fWindowState->AcquireODWindow(ev, dialog); // -- TÇ: released by CloseAndRemove
-
- if (itemHit == cancel)
- {
- ClockPart* clockPart = fClockPart; // "this" is about to go away
- fArbitrator->RelinquishFocus(ev, fModalFocus, fFrame);
- window->CloseAndRemove(ev);
- //!!! Reenable entire Menus. MenuBar object needs more support for this
- // ODReleaseObject(ev, window); // -- TÇ: released by CloseAndRemove
-
- clockPart->GetMenuBar()->EnableAll(ev);
-
- //clockPart->GetMenuBar()->EnableCommand(ev, kODCommandAbout, kODTrue ) ;
- InvalMenuBar();
- }
- else
- ODReleaseObject(ev, window);
- }
-
- return wasHandled;
- }
-
- void ClockSynchroDialogFrame::AdjustMenus(Environment *ev)
- {
- fClockPart->GetMenuBar()->EnableCommand(ev, kODCommandAbout, kODFalse ) ;
- fClockPart->GetMenuBar()->EnableCommand(ev, kODCommandCopy, kODTrue ) ;
- fClockPart->GetMenuBar()->EnableCommand(ev, kODCommandUndo, kODFalse ) ;
- fClockPart->GetMenuBar()->EnableCommand(ev, kODCommandRedo, kODFalse ) ;
- }
-
- //=========================================================================
- // ClockAlarmSettingsDialogFrame
- //=========================================================================
-
- ClockAlarmSettingsDialogFrame::ClockAlarmSettingsDialogFrame()
- {
- }
-
- ClockAlarmSettingsDialogFrame::~ClockAlarmSettingsDialogFrame()
- {
- }
-
- void ClockAlarmSettingsDialogFrame::InitClockAlarmSettingsDialogFrame(Environment* ev,
- ODSession* session,
- ODFrame* frame,
- ClockPart* clockPart)
- {
- this->InitClockDialogFrame(ev, session, frame, clockPart);
- fNeedsFoci = kODTrue;
- fShouldDeleteWindow = kODFalse; // Because its shared
- }
-
- ODBoolean ClockAlarmSettingsDialogFrame::HandleMouseDown(Environment* ev, ODFacet* facet, ODEventData* event)
- {
- ODBoolean wasHandled = kODFalse;
-
- if (IsDialogEvent((const EventRecord *)event))
- {
- short itemHit;
- ODSShort itemType;
- ODSShort checkbox;
- Handle itemHandle;
- Rect scratchRect;
-
- DialogPtr dialog;
- wasHandled = DialogSelect((const EventRecord *)event, &dialog, &itemHit);
-
- if (itemHit == kClock_SettingsCheckBoxID)
- {
- GetDialogItem(dialog, itemHit, &itemType, &itemHandle, &scratchRect);
- checkbox = GetControlValue((ControlHandle)itemHandle);
- checkbox = 1 - checkbox;
- SetControlValue((ControlHandle)itemHandle,checkbox);
- fClockPart->ToggleAlarm();
- }
- }
-
- return wasHandled;
- }
-
- //=========================================================================
- // ClockDisplaySettingsDialogFrame
- //=========================================================================
-
- ClockDisplaySettingsDialogFrame::ClockDisplaySettingsDialogFrame()
- {
- }
-
- ClockDisplaySettingsDialogFrame::~ClockDisplaySettingsDialogFrame()
- {
- }
-
- void ClockDisplaySettingsDialogFrame::InitClockDisplaySettingsDialogFrame(Environment* ev,
- ODSession* session,
- ODFrame* frame,
- ClockPart* clockPart)
- {
- this->InitClockDialogFrame(ev, session, frame, clockPart);
- fNeedsFoci = kODTrue;
- fShouldDeleteWindow = kODFalse; // Because its shared
- }
-
- ODBoolean ClockDisplaySettingsDialogFrame::HandleMouseDown(Environment* ev, ODFacet* facet, ODEventData* event)
- {
- ODBoolean wasHandled = kODFalse;
-
- if (IsDialogEvent((const EventRecord *)event))
- {
- short itemHit;
- ODSShort itemType;
- ODSShort checkbox;
- Handle itemHandle;
- Rect scratchRect;
-
- DialogPtr dialog;
- wasHandled = DialogSelect((const EventRecord *)event, &dialog, &itemHit);
-
- if (itemHit == kClock_SettingsCheckBoxID)
- {
- GetDialogItem(dialog, itemHit, &itemType, &itemHandle, &scratchRect);
- checkbox = GetControlValue((ControlHandle)itemHandle);
- checkbox = 1 - checkbox;
- SetControlValue((ControlHandle)itemHandle,checkbox);
- fClockPart->SendClockModeEvent(ev, !fClockPart->IsAnalog(),
- fClockPart->GetFirstFrame());
- }
- }
-
- return wasHandled;
- }
-
- void ClockDisplaySettingsDialogFrame::Add(Environment* ev)
- {
- #if defined(ODDebug) && ODDebugLayers
- somPrintf("ClockDisplaySettingsDialogFrame::Add\n");
- #endif
- ClockDialogFrame::Add(ev);
-
- fClockPart->AdjustDialogs(ev);
- }
-
- void ClockDisplaySettingsDialogFrame::Adjust(Environment* ev)
- {
- ODSShort itemType;
- Handle itemHandle;
- Rect scratchRect;
-
- ODWindow* window = fFrame->AcquireWindow(ev);
- DialogPtr dialog = window ? window->GetPlatformWindow(ev) : kODNULL;
- if (dialog)
- {
- GetDialogItem(dialog, kClock_SettingsCheckBoxID, &itemType, &itemHandle, &scratchRect);
- if (fClockPart->IsAnalog())
- SetControlValue((ControlHandle)itemHandle,1);
- else
- SetControlValue((ControlHandle)itemHandle,0);
- }
- ODReleaseObject(ev, window);
- }
-